﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using cms.libs;

namespace CMS
{
    public partial class ReportAccountTopWin : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                ViewState["sortOrder"] = "desc";
                ViewState["sortExpress"] = "";
                txtFromDate.SelectedDate = DateTime.Now.AddDays(-10);
                txtToDate.SelectedDate = DateTime.Now;
                BindData();
            }
        }
        protected void BindData()
        {
            DateTime fromD = txtFromDate.SelectedDate.Value;
            DateTime toD = txtToDate.SelectedDate.Value;
            DataTable lst = new DBAccountReport().GetListAccountTopWin(fromD, toD, int.Parse(drpRoom.SelectedValue));
            DataView myDataView = lst.DefaultView;
            if (sortExpress != string.Empty)
                myDataView.Sort = string.Format("{0} {1}", sortExpress, sortOrder);
            GridView1.DataSource = myDataView;
            GridView1.DataBind();
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            BindData();
        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;
            BindData();
        }

        protected void GridView1_Sorting(object sender, System.Web.UI.WebControls.GridViewSortEventArgs e)
        {
            if (ViewState["sortOrder"].ToString() == "desc")
            {
                ViewState["sortOrder"] = "asc";
            }
            else
            {
                ViewState["sortOrder"] = "desc";
            }
            ViewState["sortExpress"] = e.SortExpression;
            BindData();
        }

        public string sortExpress
        {
            get
            {
                return ViewState["sortExpress"].ToString();
            }
            set
            {
                ViewState["sortExpress"] = value;
            }
        }

        public string sortOrder
        {
            get
            {
                return ViewState["sortOrder"].ToString();
            }
            set
            {
                ViewState["sortOrder"] = value;
            }
        }
    }
}